/**
 * Created by stouduo on 2016/4/12.
 */
'use strict';

angular.module('cmsysApp').service('loginService', ['$http', function ($http) {
    var self = this;
    this.hide = true;
    this.login = function (user) {

      $http.post(baseUrl + '/user/login', user).success(function (data) {
        self.hide = data.hide;
        if (data.hide) {
          window.location.href = baseUrl + "/toIndex";
        }
      }).error(function () {
        alert('网络堵车了。。。');
      });
    }, this.hide = function () {
      return self.hide;
    }
  }])
  .controller('loginCtrl', ['$scope', '$http', '$state', '$stateParams', 'loginService',
    function ($scope, $http, $state, $stateParams, loginService) {
      $scope.hide = loginService.hide;
      $scope.user = {};
      $('#autoLogin').on('ifChecked', function (event) {
        $scope.user.autoLogin = 1;
      });
      $scope.login = function () {
        loginService.login($scope.user);
      }
    }]);
